﻿namespace Gamelight.Scene
{
	public abstract class GameSceneBase
	{
		private GameSceneBase switchSceneTo = null;

		protected abstract void Initialize();
		protected abstract void ProcessInput(Input.InputEvent[] events);
		protected abstract void Update(int gameCounter);
		protected abstract void Render(Graphics.Image gameScreen);

		// the following four functions exist so that Initialize, ProcessInput, Update, and Render can be called
		// from GameControl internally, but the user's assembly will have protected implementations of them. This
		// will hopefully prevent any confused user from thinking they must call this functions themselves
		internal void DoProcessInput(Input.InputEvent[] events)
		{
			this.ProcessInput(events);
		}

		internal void DoUpdate(int gameCounter)
		{
			this.Update(gameCounter);
		}

		internal void DoRender(Graphics.Image gameScreen)
		{
			this.Render(gameScreen);
		}

		internal void DoInitialize()
		{
			this.Initialize();
		}

		public Sound.Music DefaultMusic { get; protected set; }

		public GameControl GameHost { get { return GameControl.Instance; } }

		public GameSceneBase()
		{
			this.SoundManager = Sound.SoundManager.Instance;
			this.DefaultMusic = Sound.Music.DefaultFade;
		}

		public Sound.SoundManager SoundManager { get; internal set; }

		internal GameSceneBase SwitchTo
		{
			get { return this.switchSceneTo; }
		}

		public void SwitchToScene(GameSceneBase nextScene)
		{
			this.switchSceneTo = nextScene;
			nextScene.switchSceneTo = null;
		}

		internal bool Initialized { get; set; }
	}
}
